<?

if (!$user)
{
  include "page_personal_logon.php";
  return;
}

$PageTitle=$msg["Page_DeletePlugin"];

include "div_menu_personal.php";

$backref = "plugin?id=".$val;

if (!$_POST) 
{
  $plug = db_read_plugin_by_id($val);

  if (!check_plugin_edit_access($val, $plug))
    {return;}

  make_form( $plug, $backref );
} 
else 
{
  if (delete_plug($val)) 
  {
    print_continue($msg["PlugDeleted"], "personal_plugins");
  }
  else
  {
    print "<a href=\"$backref\">{$msg["Continue"]}</a><br><br>\n";
  }
};


//-----------------------------------------------------------------------------

function make_form($plug, $backref) 
{
  global $msg;
  global $url;
?>

<!-- Delete plug form -->

<div class="form_area">
<div class="form_div">
<form action="<?=$url;?>" method="post">

  <fieldset class="fields1">

  <dl>
    <?print_plug($plug);?>
  </dl>

  <dl class="button_div">
    <button type="submit" name="delete"><?=$msg["Delete"];?></button>
    &nbsp;
    <button type="button" name="cancel" onClick="window.location.href='<?=$backref;?>'"><?=$msg["Cancel"];?></button>
  </dl>
  </fieldset>

</form>
</div>
</div>

<?php
};


//-----------------------------------------------------------------------------

function delete_plug($id) 
{
  $n = 0;

  try 
  {
    db_call();
    db_delete_plugin($id);
  } 
  catch (Exception $e) 
  {
    $errors[$n++] = $e->getMessage();
  }

  if ($n) 
  {
    print_errors($errors);
    return False;
  }

  return True;
};

?>
